home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Button;
- import java.awt.Event;
- import java.awt.TextComponent;
- import java.awt.TextField;
-
- public class DefaultTvEventHandler implements TvEventHandler {
- Grid grid;
- int rowSelectionBase = -1;
-
- public void setupView(Grid v) {
- this.grid = v;
- }
-
- public boolean handleCellEvent(Event e, TableCell cell) {
- if (e.id != 59 && e.id != 56) {
- this.grid.clearAllSelections();
- return true;
- } else {
- return true;
- }
- }
-
- public boolean handleColHeadingEvent(Event e, TableCell cell) {
- return true;
- }
-
- public boolean handleRowHeadingEvent(Event e, TableCell cell) {
- if (e.id == 51) {
- boolean leftPressed = (e.modifiers & 8 & 4) == 0;
- if (e.shiftDown() && leftPressed) {
- if (this.grid.isSelectionBaseSet()) {
- this.grid.selectRange(cell.row() + 1, 0);
- } else {
- this.grid.setSelectionBase(cell.row() + 1, 0);
- this.grid.selectRange(cell.row() + 1, 0);
- }
- } else if (e.controlDown() && leftPressed) {
- if (!this.grid.isRangeSelected()) {
- this.grid.setSelectionBase(cell.row() + 1, 0);
- }
-
- this.grid.toggleRow(cell.row() + 1);
- } else if (leftPressed) {
- boolean set = this.grid.isRowSet(cell.row() + 1);
- this.grid.clearAllSelections();
- this.grid.setSelectionBase(cell.row() + 1, 0);
- this.grid.setRow(cell.row() + 1, !set);
- }
- }
-
- return true;
- }
-
- public boolean handleCornerCellEvent(Event e, TableCell cell) {
- return true;
- }
-
- public boolean handleToolbarEvent(Event e) {
- if (e.target instanceof TextField && e.id == 1001) {
- TextField go = (TextField)e.target;
-
- try {
- String rowText = ((TextComponent)go).getText();
- if (rowText.equals("")) {
- return true;
- }
-
- int row = Integer.parseInt(rowText);
- this.grid.gotoRow(row);
- } catch (NumberFormatException ex) {
- this.handleException((Coordinate)null, ex);
- }
- }
-
- if (e.target instanceof Button && (!(e.target instanceof Button) || e.id == 1001)) {
- Button button = (Button)e.target;
- String label = button.getLabel();
- if (label.equals(Grid.gotoRowLabel)) {
- try {
- String rowText = (String)e.arg;
- if (rowText.equals("")) {
- return true;
- }
-
- int row = Integer.parseInt(rowText);
- this.grid.gotoRow(row);
- } catch (NumberFormatException ex) {
- this.handleException((Coordinate)null, ex);
- }
- } else {
- if (label.equals(Grid.appendRowLabel)) {
- try {
- this.grid.appendRow();
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- return true;
- }
-
- if (label.equals(Grid.deleteRowLabel)) {
- int[] rows = this.grid.getSelectedRows();
- boolean auto = this.grid.getAutoRedraw();
- this.grid.setAutoRedraw(false);
-
- try {
- if (rows.length == 0) {
- Coordinate c = this.grid.getCurrentCellCoordinates();
- if (c != null) {
- this.grid.deleteRow(c.row());
- this.grid.redraw(true);
- }
- } else {
- for(int i = rows.length - 1; i >= 0; --i) {
- this.grid.deleteRow(rows[i]);
- }
- }
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- this.grid.setAutoRedraw(auto);
- this.grid.clearAllSelections();
- return true;
- }
-
- if (label.equals(Grid.insertRowLabel)) {
- int row = this.grid.getFirstSelectedRow();
-
- try {
- if (row != -1) {
- this.grid.insertRow(row);
- } else {
- Coordinate c = this.grid.getCurrentCellCoordinates();
- if (c != null) {
- this.grid.insertRow(c.row());
- this.grid.redraw(true);
- }
- }
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- this.grid.clearAllSelections();
- return true;
- }
-
- if (label.equals(Grid.saveLabel)) {
- try {
- this.grid.save();
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- return true;
- }
-
- if (label.equals(Grid.restartLabel)) {
- this.grid.restart();
- return true;
- }
-
- if (label.equals(Grid.undoRowLabel)) {
- int[] rows = this.grid.getSelectedRows();
- boolean auto = this.grid.getAutoRedraw();
- this.grid.setAutoRedraw(false);
-
- try {
- if (rows.length == 0) {
- Coordinate c = this.grid.getCurrentCellCoordinates();
- if (c != null) {
- this.grid.undoRow(c.row());
- this.grid.redraw(true);
- }
- } else {
- for(int i = rows.length - 1; i >= 0; --i) {
- this.grid.undoRow(rows[i]);
- }
- }
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- this.grid.setAutoRedraw(auto);
- this.grid.clearAllSelections();
- return true;
- }
-
- if (label.equals(Grid.undeleteRowLabel)) {
- int[] rows = this.grid.getSelectedRows();
- boolean auto = this.grid.getAutoRedraw();
- this.grid.setAutoRedraw(false);
-
- try {
- if (rows.length == 0) {
- Coordinate c = this.grid.getCurrentCellCoordinates();
- if (c != null) {
- this.grid.undeleteRow(c.row());
- this.grid.redraw(true);
- }
- } else {
- for(int i = rows.length - 1; i >= 0; --i) {
- this.grid.undeleteRow(rows[i]);
- }
- }
- } catch (TypeNotSupported ex) {
- this.handleException((Coordinate)null, ex);
- }
-
- this.grid.setAutoRedraw(auto);
- this.grid.clearAllSelections();
- return true;
- }
- }
-
- return true;
- } else {
- return false;
- }
- }
-
- public void handleException(Coordinate pos, Exception exc) {
- if (pos != null) {
- System.out.println("GRID: Error occurred at row=" + pos.row() + " col=" + pos.col());
- }
-
- ((Throwable)exc).printStackTrace();
- }
- }
-